package cn.goktech.sports.modules.contentManage.controller;

import cn.goktech.sports.common.annotation.RestAnon;
import cn.goktech.sports.common.annotation.SysLog;
import cn.goktech.sports.common.entity.Page;
import cn.goktech.sports.common.entity.R;
import cn.goktech.sports.modules.contentManage.entity.MessageEntity;
import cn.goktech.sports.modules.contentManage.entity.dto.MessageAddDTO;
import cn.goktech.sports.modules.contentManage.service.MessageService;
import cn.goktech.sports.modules.sys.controller.AbstractController;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.Objects;

/**
 * 消息内容表
 *
 * @author duanyu<>
 */
@RestController
@RequestMapping("/rest/message")
public class MessageController extends AbstractController {

	@Autowired
	private MessageService messageService;

	/**
	 * 新增
	 *
	 * @param message
	 * @return
	 */
	@SysLog("新增消息内容表")
	@PostMapping("/save")
	@RestAnon
	public R save(@RequestBody MessageAddDTO message) {
		if (Objects.isNull(message)) {
			return R.error("新增消息内容参数为空");
		}
		return messageService.saveMessage(message);
	}

	/**
	 * 列表
	 *
	 * @param params
	 * @return
	 */
	@PostMapping("/list")
	@RestAnon
	@ApiOperation(value = "消息内容列表", notes = "消息内容列表")
	public Page<MessageEntity> list(@RequestBody Map<String, Object> params) {
		return messageService.listMessage(params);
	}

	/**
	 * 根据id查询详情
	 *
	 * @param id
	 * @return
	 */
	@GetMapping("/info")
	@RestAnon
	public R getById(@RequestParam("id") Long id) {
		return messageService.getMessageById(id);
	}

	/**
	 * 修改
	 *
	 * @param message
	 * @return
	 */
	@SysLog("修改消息内容表")
	@RequestMapping("/update")
	@RestAnon
	public R update(@RequestBody MessageEntity message) {
		return messageService.updateMessage(message);
	}

	/**
	 * 删除
	 *
	 * @param id
	 * @return
	 */
	@SysLog("删除消息内容表")
	@RestAnon
	@RequestMapping("/remove")
	public R batchRemove(@RequestBody Long[] id) {
		return messageService.batchRemove(id);
	}

	/**
	 * 根据业务类型id获取消息列表
	 *
	 * @param businessId
	 * @return
	 */
	@SysLog("消息内容表")
	@GetMapping("/list")
	@RestAnon
	public R listByBusinessId(@RequestParam Long businessId) {
		return messageService.listByBusinessId(businessId);
	}
}
